package com.ruoyi.web.controller.estate;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.estate.FeeBill;
import com.ruoyi.system.service.estate.IFeeBillService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收费账单Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/estate/fee/bill")
public class FeeBillController extends BaseController
{
    @Autowired
    private IFeeBillService feeBillService;

    /**
     * 查询收费账单列表
     */
    @PreAuthorize("@ss.hasPermi('estate:fee:bill:list')")
    @GetMapping("/list")
    public TableDataInfo list(FeeBill feeBill)
    {
        startPage();
        List<FeeBill> list = feeBillService.selectFeeBillList(feeBill);
        return getDataTable(list);
    }

    /**
     * 导出收费账单列表
     */
    @PreAuthorize("@ss.hasPermi('estate:fee:bill:export')")
    @Log(title = "收费账单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(FeeBill feeBill)
    {
        List<FeeBill> list = feeBillService.selectFeeBillList(feeBill);
        ExcelUtil<FeeBill> util = new ExcelUtil<FeeBill>(FeeBill.class);
        return util.exportExcel(list, "收费账单数据");
    }

    /**
     * 获取收费账单详细信息
     */
    @PreAuthorize("@ss.hasPermi('estate:fee:bill:query')")
    @GetMapping(value = "/{billId}")
    public AjaxResult getInfo(@PathVariable("billId") Long billId)
    {
        return success(feeBillService.selectFeeBillById(billId));
    }

    /**
     * 新增收费账单
     */
    @PreAuthorize("@ss.hasPermi('estate:fee:bill:add')")
    @Log(title = "收费账单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FeeBill feeBill)
    {
        return toAjax(feeBillService.insertFeeBill(feeBill));
    }

    /**
     * 修改收费账单
     */
    @PreAuthorize("@ss.hasPermi('estate:fee:bill:edit')")
    @Log(title = "收费账单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FeeBill feeBill)
    {
        return toAjax(feeBillService.updateFeeBill(feeBill));
    }

    /**
     * 删除收费账单
     */
    @PreAuthorize("@ss.hasPermi('estate:fee:bill:remove')")
    @Log(title = "收费账单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{billIds}")
    public AjaxResult remove(@PathVariable Long[] billIds)
    {
        return toAjax(feeBillService.deleteFeeBillByIds(billIds));
    }
    
    /**
     * 缴费处理
     */
    @PreAuthorize("@ss.hasPermi('estate:fee:bill:pay')")
    @Log(title = "收费账单", businessType = BusinessType.UPDATE)
    @PostMapping("/pay")
    public AjaxResult pay(@RequestBody FeeBill feeBill)
    {
        return toAjax(feeBillService.payFeeBill(feeBill));
    }
} 